<template>
	<view>
		<uni-forms ref="form" :rules="{}">
			<uni-forms-item v-for="item,index in data" :key="index" label="" name="">
				<uni-card :title="item.title" thumbnail="" :extra="item.date" note="item.id">
					{{item.content}}
				</uni-card>
			</uni-forms-item>
		</uni-forms>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				data: [],
				pageIndex: 0,
				pageSize: 6,
				name:""
			}
		},
		onReachBottom() {
			//上拉刷新
			this.getMore()
		},
		onPullDownRefresh() {
			//开启动画
			this.getCopmment(this.name)
		},
		onLoad(option) {
			this.name = option.name
			// console.log(this.name);
			this.getCopmment(this.name)
		},
		methods:{
			getMore(){
				uni.showLoading({
					title:"加载中",
					mask:false
				})
				this.pageIndex++
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/listByPage',
					method: 'POST',
					data: {
						pageIndex:this.pageIndex,
						pageSize:this.pageSize,
						name:this.name
					},
					success: res => {
						console.log(res);
						this.data = [...this.data,...res.data.data]
						setTimeout(()=>{
							uni.hideLoading()
						},1000)
					},
					fail: () => {},
					complete: () => {}
				});
			},
			getCopmment(name){
				// console.log(name);
				uni.request({
					url: 'http://localhost:8090/freshmenapp/message/listByPage',
					method: 'POST',
					data: {
						pageIndex:this.pageIndex,
						pageSize:this.pageSize,
						name:name
					},
					success: res => {
						console.log(res);
						//结束刷新
						setTimeout(() => {
							uni.stopPullDownRefresh()
						},1000)
						this.data = res.data.data
						console.log(this.data);
					},
					fail: () => {},
					complete: () => {}
				});
			}
		}
	}
</script>

<style>
	page{
		background-color: #eee;
	}
</style>